package company.primary;

import org.iweb.html.impl.basic.Div
import org.iweb.html.impl.basic.Head
import org.iweb.html.impl.basic.Html
import org.iweb.html.impl.basic.Script
import org.iweb.html.impl.basic.Head.DefaultScript
import org.iweb.html.impl.basic.Head.DefaultStyle
import org.iweb.html.impl.basic.Head.Meta
import org.iweb.ioc.Bean
import org.iweb.ioc.Inject
import org.iweb.ui.layout.Layout

@Layout(beanName="company.primary.DefaultLayout")
@Bean(value="company.primary.DefaultLayout",singleton=false)
class DefaultLayout{

	private Html html;
	
	@Override
	public Object render(String context,String page) {
		
		//String context="/iweb";
		
		Meta m=new Meta();
		m.addAttr("name", "viewport");
		m.addAttr("content", "width=device-width, initial-scale=1.0");
		
		getHtml().getHead().append(m);// DefaultScript("/static/js/jquery-1.9.1.js"));
		
		getHtml().getHead().addStyleFile(context+"/static/css/bootstrap.css");
		getHtml().getHead().addStyleFile(context+"/static/css/bootstrap-responsive.css");
		
		DefaultStyle less=new DefaultStyle();
		less.addAttr("rel","stylesheet/less");
		less.addAttr("href",context+"/static/css/style.less");
		
		getHtml().context=context;
		
		getHtml().getHead().append(less);
		
		Div pageContainer=new Div();
		pageContainer.setId("page-container");
		pageContainer.setClassStyle("container-fluid");
		
		Div loading=new Div();
		loading.setId("loading");
		
		pageContainer.append(loading);
		
		//pageContainer.setText(content);
		
		getHtml().getBody().append(pageContainer);
		
		getHtml().getBody().append(new DefaultScript(context+"/static/js/jquery-1.10.1.js"));
		getHtml().getBody().append(new DefaultScript(context+"/static/js/jquery-migrate-1.2.1.js"));
		getHtml().getBody().append(new DefaultScript(context+"/static/js/less-1.3.3.min.js"));
		getHtml().getBody().append(new DefaultScript(context+"/static/js/bootstrap.js"));
		
		getHtml().getBody().append(new Script().setText("var portalContext='"+context+"'; var pageName='"+page+"'"));
		
		getHtml().getBody().append(new DefaultScript(context+"/static/js/internal.js"));
		
		return getHtml();
		
	}
	
	public Html getHtml() {
		return html;
	}
	
	@Inject(id="org.iweb.html.Html")
	public void setHtml(Html html) {
		this.html = html;
	}
	
}